//== SAGITTARIUS ============================================================================

//== BEGINNING OF CODE ===============================================================

#include "sagittarius/core/SagittariusCore.h"
#include "sagittarius/lexer/lexcore.h"
#include "sagittarius/io/io.h"
#include <string.h>

/// sg_lex_buf2str
std::string sg_lex_buf2stdstrl(constLexBuf b, uint64 l) {
    LexBuf bb = (LexBuf)LX_CREATE_BUFFER(l+1);
    LX_COPY(bb, b, l);
    LX_ALPHA_SET_SPC(bb[l], '\0');
    {
        size_t encl = LX_ENCBUFFER_LEN(bb);
        char* str=(char*)malloc(encl);
        LX_BUFFER_ENC_UTF8(bb, str);
        LX_FREE_BUFFER(bb);
        
        std::string s(str);
        free(str);
        return s;
    }
}